<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学生编号" prop="stuId">
        <el-input v-model="queryParams.stuId" placeholder="请输入学生编号" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="工作单位" prop="workUnit">
        <el-input v-model="queryParams.workUnit" placeholder="请输入工作单位" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="社区" prop="commnunity">
        <el-input v-model="queryParams.commnunity" placeholder="请输入社区" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="执业范围" prop="practiceRange">
        <el-input v-model="queryParams.practiceRange" placeholder="请输入执业范围" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="上岗证编号" prop="postsNumber">
        <el-input v-model="queryParams.postsNumber" placeholder="请输入上岗证编号" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="岗位" prop="posts">
        <el-input v-model="queryParams.posts" placeholder="请输入岗位" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="颁证时间" prop="certTime">
        <el-date-picker clearable v-model="queryParams.certTime" type="date" value-format="yyyy-MM-dd" placeholder="请选择颁证时间"></el-date-picker>
      </el-form-item>
      <el-form-item label="参加初训年份" prop="initialTraining">
        <el-input v-model="queryParams.initialTraining" placeholder="请输入参加初训年份" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="备注" prop="comment">
        <el-input v-model="queryParams.comment" placeholder="请输入备注" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="证件号" prop="docNumber">
        <el-input v-model="queryParams.docNumber" placeholder="请输入证件号" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="机构编号" prop="organizationId">
        <el-input v-model="queryParams.organizationId" placeholder="请输入机构编号" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="班级编号" prop="traning">
        <el-input v-model="queryParams.traning" placeholder="请输入班级编号" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="用户编号" prop="userNumber">
        <el-input v-model="queryParams.userNumber" placeholder="请输入用户编号" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="预留字段1" prop="reservedOne">
        <el-input v-model="queryParams.reservedOne" placeholder="请输入预留字段1" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="预留字段2" prop="reservedTwo">
        <el-input v-model="queryParams.reservedTwo" placeholder="请输入预留字段2" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['pv:stu_record:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['pv:stu_record:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['pv:stu_record:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['pv:stu_record:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="stu_recordList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
<!--      <el-table-column label="主键" align="center" prop="id"/>-->
      <el-table-column label="学生编号" align="center" prop="stuId"/>
      <el-table-column label="工作单位" align="center" prop="workUnit"/>
      <el-table-column label="社区" align="center" prop="commnunity"/>
      <el-table-column label="执业范围" align="center" prop="practiceRange"/>
      <el-table-column label="执业类别" align="center" prop="praticeType"/>
      <el-table-column label="上岗证编号" align="center" prop="postsNumber"/>
      <el-table-column label="岗位" align="center" prop="posts"/>
      <el-table-column label="颁证时间" align="center" prop="certTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.certTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="参加初训年份" align="center" prop="initialTraining"/>
      <el-table-column label="备注" align="center" prop="comment"/>
      <el-table-column label="证件号" align="center" prop="docNumber"/>
      <el-table-column label="机构编号" align="center" prop="organizationId"/>
      <el-table-column label="班级编号" align="center" prop="traning"/>
      <el-table-column label="状态" align="center" prop="status"/>
      <el-table-column label="用户编号" align="center" prop="userNumber"/>
      <el-table-column label="预留字段1" align="center" prop="reservedOne"/>
      <el-table-column label="预留字段2" align="center" prop="reservedTwo"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['pv:stu_record:edit']">修改
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['pv:stu_record:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList"/>

    <!-- 添加或修改学员报名记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="学生编号" prop="stuId">
          <el-input v-model="form.stuId" placeholder="请输入学生编号"/>
        </el-form-item>
        <el-form-item label="工作单位" prop="workUnit">
          <el-input v-model="form.workUnit" placeholder="请输入工作单位"/>
        </el-form-item>
        <el-form-item label="社区" prop="commnunity">
          <el-input v-model="form.commnunity" placeholder="请输入社区"/>
        </el-form-item>
        <el-form-item label="执业范围" prop="practiceRange">
          <el-input v-model="form.practiceRange" placeholder="请输入执业范围"/>
        </el-form-item>
        <el-form-item label="上岗证编号" prop="postsNumber">
          <el-input v-model="form.postsNumber" placeholder="请输入上岗证编号"/>
        </el-form-item>
        <el-form-item label="岗位" prop="posts">
          <el-input v-model="form.posts" placeholder="请输入岗位"/>
        </el-form-item>
        <el-form-item label="颁证时间" prop="certTime">
          <el-date-picker clearable v-model="form.certTime" type="date" value-format="yyyy-MM-dd" placeholder="请选择颁证时间"></el-date-picker>
        </el-form-item>
        <el-form-item label="参加初训年份" prop="initialTraining">
          <el-input v-model="form.initialTraining" placeholder="请输入参加初训年份"/>
        </el-form-item>
        <el-form-item label="备注" prop="comment">
          <el-input v-model="form.comment" placeholder="请输入备注"/>
        </el-form-item>
        <el-form-item label="证件号" prop="docNumber">
          <el-input v-model="form.docNumber" placeholder="请输入证件号"/>
        </el-form-item>
        <el-form-item label="机构编号" prop="organizationId">
          <el-input v-model="form.organizationId" placeholder="请输入机构编号"/>
        </el-form-item>
        <el-form-item label="班级编号" prop="traning">
          <el-input v-model="form.traning" placeholder="请输入班级编号"/>
        </el-form-item>
        <el-form-item label="用户编号" prop="userNumber">
          <el-input v-model="form.userNumber" placeholder="请输入用户编号"/>
        </el-form-item>
        <el-form-item label="预留字段1" prop="reservedOne">
          <el-input v-model="form.reservedOne" placeholder="请输入预留字段1"/>
        </el-form-item>
        <el-form-item label="预留字段2" prop="reservedTwo">
          <el-input v-model="form.reservedTwo" placeholder="请输入预留字段2"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listStu_record, getStu_record, delStu_record, addStu_record, updateStu_record} from "@/api/pv/stu_record";

export default {
  name: "Stu_record",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 学员报名记录表格数据
      stu_recordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        stuId: null,
        workUnit: null,
        commnunity: null,
        practiceRange: null,
        praticeType: null,
        postsNumber: null,
        posts: null,
        certTime: null,
        initialTraining: null,
        comment: null,
        docNumber: null,
        organizationId: null,
        traning: null,
        status: null,
        userNumber: null,
        reservedOne: null,
        reservedTwo: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询学员报名记录列表 */
    getList() {
      this.loading = true;
      listStu_record(this.queryParams).then(response => {
        this.stu_recordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        stuId: null,
        workUnit: null,
        commnunity: null,
        practiceRange: null,
        praticeType: null,
        postsNumber: null,
        posts: null,
        certTime: null,
        initialTraining: null,
        comment: null,
        docNumber: null,
        organizationId: null,
        traning: null,
        status: null,
        userNumber: null,
        reservedOne: null,
        reservedTwo: null,
        createTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加学员报名记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getStu_record(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改学员报名记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateStu_record(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addStu_record(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除学员报名记录编号为"' + ids + '"的数据项？').then(function () {
        return delStu_record(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('pv/stu_record/export', {
        ...this.queryParams
      }, `stu_record_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
